package com.gxa.feedback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.R;

import com.gxa.common.entity.platform_maintenance_service1001.PlatformNotice;
import com.gxa.feedback.mapper.PlatFormNoticeMapper;
import com.gxa.feedback.service.PlatFormNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class PlatFormNoticeServiceImpl implements PlatFormNoticeService {

    @Autowired
    private PlatFormNoticeMapper platFormNoticeMapper;

    @Override
    public R selectPlatFormNoticeByPage(Integer currentPage, Integer pageSize) {
        R r = new R();
        QueryWrapper<PlatformNotice> queryWrapper = new QueryWrapper<>();
        Page<PlatformNotice> feedbackPage = new Page<>(currentPage,pageSize);
        Page<PlatformNotice> selectPage = platFormNoticeMapper.selectPage(feedbackPage, queryWrapper);
        r.setCode(200);
        r.setMessage("查询分页成功");
        r.setData(selectPage);
        return r;
    }

    @Override
    public R updatePlatFormNotice(PlatformNotice platformNotice) {

        System.out.println(platformNotice);

        R r = new R();
        PlatformNotice platformNotice1 = platFormNoticeMapper.selectById(platformNotice.getId());

        System.out.println(platformNotice1);

        if(platformNotice1.getStatus() == 1 || platformNotice1.getStatus() == 2){
            platformNotice1=platformNotice;
            System.out.println(platformNotice1);
            int result = platFormNoticeMapper.updateById(platformNotice1);
            PlatformNotice platformNotice2 = platFormNoticeMapper.selectById(platformNotice1.getId());

            System.out.println(platformNotice2);

            r.setCode(200);
            r.setMessage("修改成功");
            r.setData(result);
            r.setData(platformNotice2);
        }else {
            r.setCode(200);
            r.setData(platformNotice);
            r.setMessage("已经为发布，不需要发布");
        }
        return r;
    }

    @Override
    public R selectPlatFormNotice(PlatformNotice platformNotice) {
        R r = new R();
        List<PlatformNotice> platformNoticeList = platFormNoticeMapper.selectPlatFormNotice(platformNotice);
        r.setCode(200);
        r.setMessage("条件查询成功");
        r.setData(platformNoticeList);
        return r;
    }

    @Override
    public R delPlatFormNoticeByIdS(List<Integer> ids) {
        R r = new R();
        int result = platFormNoticeMapper.delPlatFormNoticeByIdS(ids);
        if(result > 0){
            r.setCode(200);
            r.setMessage("删除成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("删除失败");
        }
        return r;
    }

    @Override
    public R addPlatFormNotice(PlatformNotice platformNotice) {

        R r = new R();
        int result = platFormNoticeMapper.insert(platformNotice);

        if(result > 0){
            r.setCode(200);
            r.setMessage("添加成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("添加失败");
        }
        return r;
    }

    @Override
    public R selectAll() {
        R r = new R();
        List<PlatformNotice> platformNoticeList = platFormNoticeMapper.selectAll();
        r.setCode(200);
        r.setMessage("查询成功");
        r.setData(platformNoticeList);
        return r;
    }

    @Override
    public R selectPlatFormById(PlatformNotice platformNotice) {
        R r = new R();

        PlatformNotice selectById = platFormNoticeMapper.selectById(platformNotice.getId());
        r.setCode(200);
        r.setMessage("根据id查询成功");
        r.setData(selectById);
        return r;
    }

    @Override
    public R stopPlatFormById(long id) {
        R r = new R();
        int result = platFormNoticeMapper.stopPlatFormById(id);
        if(result > 0){
            r.setCode(200);
            r.setMessage("停用成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("停用失败失败");
        }
        return r;

    }
}
